<?php

namespace App\Http\Controllers\API\LifeCycle\User;
/**
 * Created by PhpStorm.
 * User: 共赢岛
 * Date: 2023/12/13
 * Time: 11:12
 */
use App\Http\Controllers\Controller;
use App\Http\Resources\UserCarInfoResource;
use App\Services\LifeCycle\UserService;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;

class UserController extends Controller
{
    public function saveUserInfo(Request $request)
    {
        UserService::saveUserInfo($request->all());

        return $this->success();
    }

    public function userCarInfo()
    {
        $user = UserService::carOne();

        return $this->success(new UserCarInfoResource($user));
    }

    public function userInfo()
    {
        $user = Auth::user();
        $user->platform_phone = '-';
        $user->balance = $user->balance ?? 0;
        $user->package_attr_permission_ids = json_decode($user->package_attr_permission_ids, true);

        return $this->success($user);
    }

    public function verifyOldUser(Request $request)
    {

        $save = UserService::verifyOldUser($request->all());

        if ($save['code'] == 200) {
            return $this->success();
        } else {
            return $this->failure($save['message']);
        }
    }
}